package com.szsfm.vehiclemanagement.util;

import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.view.Display;
import android.view.WindowManager;

/**
 * Created by zhoubigbo on 2017/11/20.
 */
public class DeviceUtil {

    public static int getScreenWidth(Activity context) {
        return getDisplay(context).getWidth();
    }

    public static int getScreenHeight(Activity context) {
        return getDisplay(context).getHeight();
    }

    private static Display getDisplay(Activity context) {
        WindowManager windowManager = context.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        return display;
    }

    public static String getProductName(){
        return android.os.Build.MODEL;
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }


    /**
     * 获取设备sim号
     *
     * @param context
     * @return
     */
    public static String getImei(Context context) {
        try {
            return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

}
